﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HumanManagement.BusinessLogic;
using HumanManagement.BusinessObjects;

namespace BSC_HumanManagement.Usercontrols
{
    public partial class uc_TinhTrangHonNhan : System.Web.UI.UserControl
    {
        Code.Staticvariable _objStaticvariable = new Code.Staticvariable();
        int stt = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            _objStaticvariable.CheckPermission(this);
            LoadData();
        }

        private void LoadData()
        {
            MaritalStatusBL _objMaritalStatusBL = new MaritalStatusBL();
            DataTable _objDataTable = _objMaritalStatusBL.GetDataSet(int.Parse(Session["PersonalProfileID"].ToString())).Tables[0];
            
            this._GridView.DataSource = _objDataTable;
            this._GridView.DataBind();
            // ẩn cột mã Nhân viên
            this._GridView.Columns[1].Visible = false;
            // ẩn cột mã hợp đồng
            this._GridView.Columns[3].Visible = false;
        }

        protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this._GridView.PageIndex = e.NewPageIndex;
            this._GridView.DataBind();
        }

        protected void _GridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                stt++;
                Label lblSTT = e.Row.Cells[0].FindControl("lblSTT") as Label;
                lblSTT.Text = stt.ToString();

                Label lblFullName = e.Row.Cells[2].FindControl("lblFullName") as Label;
                // Cell[2] : ID ẩn của Mã hồ sơ nhân viên
                lblFullName.Text = _objStaticvariable.GetPersonalProfile_FullName_ByID(Convert.ToInt32(e.Row.Cells[1].Text), Convert.ToInt32(Session["PersonalProfileID"]));

                Label lblMaritalName = e.Row.Cells[4].FindControl("lblMaritalType") as Label;
                // Cell[4] : ID ẩn của Mã hop dong
                lblMaritalName.Text = _objStaticvariable.GetMaritalType_Name_ByID(Convert.ToInt32(e.Row.Cells[3].Text));

                // 1: true
                if (e.Row.Cells[7].Text.Equals("1"))
                {
                    e.Row.Cells[7].Text = "Mở";
                }
                else
                {
                    e.Row.Cells[7].Text = "Đóng";
                }
            }
        }
    }
}